From b379bc580e1fa5a65bfbfbe6625404b06805b5be Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Fri, 20 Feb 2004 23:21:01 +0000 Subject: [PATCH] conditional compile for GtkPathBar Fri Feb 20 18:20:22 2004 Jonathan Blandford * gtk/gtkfilechooserdefault.c: conditional compile for GtkPathBar * gtk/gtkpathbar.c (gtk_path_bar_size_allocate): Clean up allocation code. Works fully in RTL languages, I think. (gtk_path_bar_scroll_up): Scroll up. (gtk_path_bar_scroll_down): Scroll down. --- ChangeLog | 9 ++++ ChangeLog.pre-2-10 | 9 ++++ ChangeLog.pre-2-4 | 9 ++++ ChangeLog.pre-2-6 | 9 ++++ ChangeLog.pre-2-8 | 9 ++++ gtk/gtkfilechooserdefault.c | 11 +++++ gtk/gtkpathbar.c | 98 ++++++++++++++++++++++++++++++++----- gtk/gtkpathbar.h | 1 + 8 files changed, 143 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1abe31265..b559a8fc55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Feb 20 18:20:22 2004 Jonathan Blandford + + * gtk/gtkfilechooserdefault.c: conditional compile for GtkPathBar + + * gtk/gtkpathbar.c (gtk_path_bar_size_allocate): Clean up + allocation code. Works fully in RTL languages, I think. + (gtk_path_bar_scroll_up): Scroll up. + (gtk_path_bar_scroll_down): Scroll down. + 2004-02-20 Christian Rose * configure.in: Added "en_CA" to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index f1abe31265..b559a8fc55 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +Fri Feb 20 18:20:22 2004 Jonathan Blandford + + * gtk/gtkfilechooserdefault.c: conditional compile for GtkPathBar + + * gtk/gtkpathbar.c (gtk_path_bar_size_allocate): Clean up + allocation code. Works fully in RTL languages, I think. + (gtk_path_bar_scroll_up): Scroll up. + (gtk_path_bar_scroll_down): Scroll down. + 2004-02-20 Christian Rose * configure.in: Added "en_CA" to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index f1abe31265..b559a8fc55 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,12 @@ +Fri Feb 20 18:20:22 2004 Jonathan Blandford + + * gtk/gtkfilechooserdefault.c: conditional compile for GtkPathBar + + * gtk/gtkpathbar.c (gtk_path_bar_size_allocate): Clean up + allocation code. Works fully in RTL languages, I think. + (gtk_path_bar_scroll_up): Scroll up. + (gtk_path_bar_scroll_down): Scroll down. + 2004-02-20 Christian Rose * configure.in: Added "en_CA" to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index f1abe31265..b559a8fc55 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +Fri Feb 20 18:20:22 2004 Jonathan Blandford + + * gtk/gtkfilechooserdefault.c: conditional compile for GtkPathBar + + * gtk/gtkpathbar.c (gtk_path_bar_size_allocate): Clean up + allocation code. Works fully in RTL languages, I think. + (gtk_path_bar_scroll_up): Scroll up. + (gtk_path_bar_scroll_down): Scroll down. + 2004-02-20 Christian Rose * configure.in: Added "en_CA" to ALL_LINGUAS. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index f1abe31265..b559a8fc55 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +Fri Feb 20 18:20:22 2004 Jonathan Blandford + + * gtk/gtkfilechooserdefault.c: conditional compile for GtkPathBar + + * gtk/gtkpathbar.c (gtk_path_bar_size_allocate): Clean up + allocation code. Works fully in RTL languages, I think. + (gtk_path_bar_scroll_up): Scroll up. + (gtk_path_bar_scroll_down): Scroll down. + 2004-02-20 Christian Rose * configure.in: Added "en_CA" to ALL_LINGUAS. diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index cee3e6b0fc..7c4cc47935 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -39,6 +39,7 @@ #include "gtklabel.h" #include "gtkmenuitem.h" #include "gtkmessagedialog.h" +#include "gtkpathbar.h" #include "gtkprivate.h" #include "gtkscrolledwindow.h" #include "gtksizegroup.h" @@ -119,6 +120,7 @@ struct _GtkFileChooserDefault GtkWidget *entry; GtkWidget *preview_widget; GtkWidget *extra_widget; + GtkWidget *path_bar; GtkTreeViewColumn *list_name_column; GtkCellRenderer *list_name_renderer; @@ -1556,7 +1558,13 @@ file_pane_create (GtkFileChooserDefault *impl) /* Current folder indicator */ widget = current_folder_create (impl); + impl->path_bar = g_object_new (gtk_path_bar_get_type (), NULL); + gtk_widget_show_all (impl->path_bar); +#ifdef USE_PATH_BAR + gtk_box_pack_start (GTK_BOX (vbox), impl->path_bar, FALSE, FALSE, 0); +#else gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); +#endif /* Box for lists and preview */ @@ -2215,6 +2223,9 @@ gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser, str = g_strdup_printf (_("Current folder: %s"), gtk_file_path_get_string (path)); gtk_label_set_text (GTK_LABEL (impl->folder_label), str); +#ifdef USE_PATH_BAR + gtk_path_bar_set_path (GTK_PATH_BAR (impl->path_bar), gtk_file_path_get_string (path)); +#endif g_free (str); /* Update the folder tree */ diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c index b0fed6ca50..f1aa776366 100644 --- a/gtk/gtkpathbar.c +++ b/gtk/gtkpathbar.c @@ -41,6 +41,8 @@ static void gtk_path_bar_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); +static void gtk_path_bar_scroll_up (GtkWidget *button, GtkPathBar *path_bar); +static void gtk_path_bar_scroll_down (GtkWidget *button, GtkPathBar *path_bar); static GtkWidget * get_slider_button (GtkPathBar *path_bar) @@ -64,6 +66,9 @@ gtk_path_bar_init (GtkPathBar *path_bar) path_bar->spacing = 3; path_bar->up_slider_button = get_slider_button (path_bar); path_bar->down_slider_button = get_slider_button (path_bar); + + g_signal_connect (path_bar->up_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_up), path_bar); + g_signal_connect (path_bar->down_slider_button, "clicked", G_CALLBACK (gtk_path_bar_scroll_down), path_bar); } static void @@ -88,7 +93,8 @@ gtk_path_bar_class_init (GtkPathBarClass *path_bar_class) container_class->add = gtk_path_bar_add; container_class->forall = gtk_path_bar_forall; container_class->remove = gtk_path_bar_remove; - // container_class->child_type = gtk_path_bar_child_type; + /* FIXME: */ + /* container_class->child_type = gtk_path_bar_child_type;*/ } @@ -236,9 +242,10 @@ gtk_path_bar_size_allocate (GtkWidget *widget, gboolean reached_end = FALSE; gint slider_space = 2 * (path_bar->spacing + path_bar->slider_width); - /* FIXME: first_button will be something else if we've scrolled - */ - first_button = path_bar->button_list; + if (path_bar->first_scrolled_button) + first_button = path_bar->first_scrolled_button; + else + first_button = path_bar->button_list; need_sliders = TRUE; /* To see how much space we have, and how many buttons we can display. @@ -301,30 +308,27 @@ gtk_path_bar_size_allocate (GtkWidget *widget, } } - for (list = first_button; list; list = list->prev) { child = GTK_WIDGET (list->data); child_allocation.width = child->requisition.width; + if (direction == GTK_TEXT_DIR_RTL) + child_allocation.x -= child_allocation.width; /* Check to see if we've don't have any more space to allocate buttons */ if (need_sliders && direction == GTK_TEXT_DIR_RTL) { - if (child_allocation.x - child_allocation.width - 2 * path_bar->spacing - path_bar->spacing < - widget->allocation.x + border_width) + if (child_allocation.x - path_bar->spacing - path_bar->slider_width < widget->allocation.x + border_width) break; } else if (need_sliders && direction == GTK_TEXT_DIR_LTR) { - if (child_allocation.x + child_allocation.width + 2 * path_bar->spacing + path_bar->spacing > + if (child_allocation.x + child_allocation.width + path_bar->spacing + path_bar->slider_width > widget->allocation.x + border_width + allocation_width) break; } - if (direction == GTK_TEXT_DIR_RTL) - child_allocation.x -= child_allocation.width; - gtk_widget_set_child_visible (list->data, TRUE); gtk_widget_size_allocate (child, &child_allocation); @@ -447,6 +451,75 @@ gtk_path_bar_forall (GtkContainer *container, (* callback) (path_bar->down_slider_button, callback_data); } +static void + gtk_path_bar_scroll_down (GtkWidget *button, GtkPathBar *path_bar) +{ + GList *list; + GList *down_button, *up_button; + gint space_available; + gint space_needed; + gint border_width; + GtkTextDirection direction; + + border_width = GTK_CONTAINER (path_bar)->border_width; + direction = gtk_widget_get_direction (GTK_WIDGET (path_bar)); + + /* We find the button at the 'down' end that we have to make + * visible */ + for (list = path_bar->button_list; list; list = list->next) + { + if (list->next && gtk_widget_get_child_visible (GTK_WIDGET (list->next->data))) + { + down_button = list; + break; + } + } + + /* Find the last visible button on the 'up' end + */ + for (list = g_list_last (path_bar->button_list); list; list = list->prev) + { + if (gtk_widget_get_child_visible (GTK_WIDGET (list->data))) + { + up_button = list; + break; + } + } + + space_needed = GTK_WIDGET (down_button->data)->allocation.width + path_bar->spacing; + if (direction == GTK_TEXT_DIR_RTL) + space_available = GTK_WIDGET (path_bar)->allocation.x + GTK_WIDGET (path_bar)->allocation.width; + else + space_available = (GTK_WIDGET (path_bar)->allocation.x + GTK_WIDGET (path_bar)->allocation.width - border_width) - + (path_bar->down_slider_button->allocation.x + path_bar->down_slider_button->allocation.width); + + /* We have space_available extra space that's not being used. We + * need space_needed space to make the button fit. So we walk down + * from the end, removing buttons until we get all the space we + * need. */ + while (space_available < space_needed) + { + space_available += GTK_WIDGET (up_button->data)->allocation.width + path_bar->spacing; + up_button = up_button->prev; + path_bar->first_scrolled_button = up_button; + } +} + +static void + gtk_path_bar_scroll_up (GtkWidget *button, GtkPathBar *path_bar) +{ + GList *list; + + for (list = g_list_last (path_bar->button_list); list; list = list->prev) + { + if (list->prev && gtk_widget_get_child_visible (GTK_WIDGET (list->prev->data))) + { + path_bar->first_scrolled_button = list; + return; + } + } +} + /* Public functions. */ @@ -526,12 +599,13 @@ gtk_path_bar_set_path (GtkPathBar *path_bar, label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), label_str); gtk_container_add (GTK_CONTAINER (button), label); - // gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); button_list = g_list_prepend (button_list, button); gtk_container_add (GTK_CONTAINER (path_bar), button); + gtk_widget_show_all (button); } path_bar->button_list = g_list_reverse (button_list); + gtk_widget_queue_resize (GTK_WIDGET (path_bar)); } diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h index c2129f56bc..0fcee4b761 100644 --- a/gtk/gtkpathbar.h +++ b/gtk/gtkpathbar.h @@ -41,6 +41,7 @@ struct _GtkPathBar const char *path; GList *button_list; + GList *first_scrolled_button; gint16 slider_width; gint16 spacing; gint16 button_offset; -- 2.30.2